<template>
  <div class="lab-button-group" >
    <div class="lab-button-group-layout" :style="{justifyContent: element.props.align }">
      <div v-for="(item,itemIndex) in showButtons" :key="item.key" >
        <lab-element :class="{ 'active': item.key === labDesign.activity.key }" :element="item" :elements="element.elements" :index="itemIndex" :model-data="modelData" />
      </div>
      <el-dropdown v-if="element.props.showCount < element.elements.length" type="primary" :hide-on-click="false">
        <lab-element :class="{ 'active': element.elements[element.props.showCount - 1].key === labDesign.activity.key }" :element="element.elements[element.props.showCount - 1]" :elements="element.elements" :index="element.props.showCount - 1" :model-data="modelData" />
        <el-dropdown-menu slot="dropdown">
          <template v-for="(item, itemIndex) in element.elements">
            <el-dropdown-item v-if="itemIndex >= element.props.showCount" :key="item.key" style="margin: 4px 0 ">
              <lab-element :class="{ 'active': item.key === labDesign.activity.key }" :element="item" :elements="element.elements" :index="itemIndex" :model-data="modelData" />
            </el-dropdown-item>
          </template>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import LabBase from "../../mixins/LabBase";
import LabDrag from "../../mixins/LabDrag";
import LabEvent from "../../mixins/LabEvent";

export default {
  name: "LabButtonGroup",
  mixins: [LabBase, LabDrag, LabEvent],
  computed: {
    showButtons() {
      const { showCount } = this.element.props
      const list = this.element.elements.filter(item => this.condition(item) || item.visible)
      const length = list.length
      if (showCount >= length) {
        return list
      }
      const shows = []
      for (let i = 0; i < showCount - 1; i++) {
        shows.push(list[i])
      }
      return shows
    }
  },
  created() {
    this.$LabRender.autoFill(this.element, this)
  }
}
</script>

<style lang="scss">
  .lab-button-group {
    width: 100%;
    height: 100%;
    &-layout{
      //min-height: 30px;
      display: flex;
      flex-flow: row nowrap;
      justify-content: flex-start;
      align-items: center;
      .el-button {
        margin-right: 2px;
      }
    }
  }
</style>
